#!/usr/bin/python

import os
import wx

if __name__=='__main__':
	raise "Can not execute this module directly, must import it."

# --------------------------------- STAGE 1 ----------------------------------

#import startup

#app = startup.stage1() # don't have configuration_dir here, use paths.get_configuration_dir()
app = wx.PySimpleApp()
app.SetAppName('farmhand')

# --------------------------------- STAGE 2 ----------------------------------
# These module do not use this, "fm", module

from base           import *
from paths          import get_user_settings_module_path, get_default_settings_dump_path,get_persistent_state_savefile_path, \
                           get_configuration_dir
from plat           import if_Mac_Unix_Win
from other          import EventSet, platform_eol, figure_out_eol, samefile
from color          import Gray, brighten, add_transparency, random_color, random_pen, random_brush, interpolate
from paranoia       import safer_save
from version        import VERSION, VERNUMBER, version_summary
from lru            import LeastRecentlyUsed

import debug

DEBUG=debug.ON

import eventbus

EventBus=eventbus.EventBus()


# --------------------------------- STAGE 3 ----------------------------------
# Set up configuration

configuration_dir = get_configuration_dir()
 
if not os.path.exists(configuration_dir): os.makedirs(configuration_dir)

import configuration

if not os.path.exists(get_user_settings_module_path()): configuration.make_initial_user_settings_file()

persistent_state=configuration._PersistentStateSingleton(get_persistent_state_savefile_path()) # ?? needs shorter name

State=persistent_state # ?? get rid of "persistent_state"

settings=configuration._GlobalSettingsSingleton()

Settings=settings # ?? remove "settings"

# --------------------------------- STAGE 4 ----------------------------------
# Import modules that use this, "fm", module and thus populate Settings

settings.push_mode(settings.DEFAULTS_MODE)

# the following imports, among other things, populate settings with defaults
import textstyle

from modes                   import DefaultMode
from textbar                 import Textbar
from document.document       import Document
from mainframe               import reset_status_text,set_status_text,short_duration_status_text
from log                     import warn

settings.for_reference_dump_default_settings()

settings.load_user_settings(need_reload=False)

settings.push_mode(settings.USER_SET_THROUGH_GUI)

# from this point forward, all settings set will be "automatically managed"
# which means they'll be saved in a special section of the user settings file

UNCHANGED,SAVED,UNSAVED=range(3)

# --------------------------------- STAGE 5 ----------------------------------
# Construct the top frame

#print "fm.b4 stage3>"
#print str(debug.stack())

import mainframe

main_frame = mainframe.MainFrame()
main_panel = main_frame.main_panel

main_frame.Show()

#print "fm.after stage3>"

# --------------------------------- STAGE 6 ----------------------------------
# Let's go!
	
def main_loop_():
	reset_status_text()
	app.MainLoop()
